package org.nio;

import io.netty.channel.DefaultEventLoop;
import io.netty.util.concurrent.DefaultPromise;

/**
 * @author wind
 * @create 2025-01-16 16:01
 */
public class EventLoopAsync {
    public static void main(String[] args) {
        DefaultEventLoop eventExecutors = new DefaultEventLoop();
        DefaultPromise<Integer> promise = new DefaultPromise<>(eventExecutors);

        promise.addListener(future -> {
            //log.debug("result {}", (promise.isSuccess() ? promise.getNow() : promise.cause()).toString());
            System.out.println("result {}"+ (promise.isSuccess() ? promise.getNow() : promise.cause()).toString());
        });

        eventExecutors.execute(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            RuntimeException e = new RuntimeException("error...");
            //log.debug("set failure, {}", e.toString());
            System.out.println("set failure, {} "+ e.toString());
            promise.setFailure(e);
        });
        System.out.println("start...");
        //log.debug("start...");
    }
}
